package com.ysx.oa.student.controller;

import com.ysx.oa.clazz.bean.ClazzBean;
import com.ysx.oa.delay.bean.DelayBean;
import com.ysx.oa.delay.service.DelayService;
import com.ysx.oa.holiday.bean.HolidayBean;
import com.ysx.oa.holiday.service.HolidayService;
import com.ysx.oa.student.bean.StudentBean;
import com.ysx.oa.student.entity.StudentEntity;
import com.ysx.oa.student.service.StudentService;
import com.ysx.oa.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {


    @Autowired
    private StudentService studentService;
    @Autowired
    private HolidayService holidayService;
    @Autowired
    private DelayService delayService;

    /*
     * 方法描述:修改学生信息
     * @author: 尹泳超
     * @date: 2021/11/22 14:22
     * @params: [userBeans]
     * @returns:java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/updateStudentMessageByStudentId",method = RequestMethod.POST)
    public Map<String,Object> updateStudentMessageByStudentId(@RequestBody StudentBean studentBean){
        Map<String,Object> map = new HashMap();
        studentService.updateStudentEducationById(studentBean);

        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }

    /*
     * 方法描述:通过ClassId找到这个班的所有的学生
     * @author: 尹泳超
     * @date: 2021/11/22 14:16
     * @params: [classId]
     * @returns:java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/findStudentListByClassId",method = RequestMethod.GET)
    public Map<String,Object> findStudentList(Integer classId){
        List<UserBean> studentList = studentService.findStudentListByClassId(classId);

        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("message","success");
        map.put("data",studentList);
        return map;
    }


    /*
     * 方法描述:通过学生ID找到班级的信息
     * @author: 尹泳超
     * @date: 2021/11/22 14:19
     * @params: [studentId]
     * @returns:java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/findClassByStudentId",method = RequestMethod.GET)
    public Map<String,Object> findClass(Integer studentId){
        ClazzBean classBean = studentService.findClassByStudentID(studentId);
        Map<String,Object> map = new HashMap();

        map.put("code",200);
        map.put("message","success");
        map.put("data",classBean);
        return map;
    }



    /*
     * 方法描述:通过班级ID找到这个班的老师
     * @author: 尹泳超
     * @date: 2021/11/22 14:19
     * @params: [ClassID]
     * @returns:java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/findTeacherByClassID",method = RequestMethod.GET)
    public Map<String,Object> findTeacher(Integer classId){
        UserBean teacher = studentService.findTeacherByClassID(classId);


        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("message","success");
        map.put("data",teacher);
        return map;
    }


    /*
     * 方法描述:查找学生的信息
     * @author: 尹泳超
     * @date: 2021/11/23 15:30
     * @params: [studentId]
     * @returns:java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/findStudentMessageByStudentId",method = RequestMethod.GET)
    public Map<String,Object> findStudentMessageByStudentId(HttpServletRequest request){

        Integer studentId = (Integer) request.getSession().getAttribute("id");
        Map<String,Object> map = new HashMap();

        StudentEntity studentMessage = studentService.findStudentMessageByStudentId(studentId);
        map.put("code",200);
        map.put("message","success");
        map.put("data",studentMessage);
        return map;
    }

    @RequestMapping(value = "/findHolidayByStudentId",method = RequestMethod.GET)
    public Map<String,Object> findHolidayByStudentId(Integer Id){
        Map<String,Object> map = new HashMap();

        List<HolidayBean> studentHoliday = holidayService.findByStudent(Id);
        map.put("code",200);
        map.put("message","success");
        map.put("data",studentHoliday);
        return map;
    }


    @RequestMapping(value = "/findDelayRecordByStudentId" ,method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findDelayRecordByStudentId( @RequestBody DelayBean bean){
        Map<String,Object> map = new HashMap<>();

        List<DelayBean> delayRecord = delayService.findDelayRecord(bean);
        map.put("result",delayRecord);
        return map;

    }











}
